
const emailRule = /^[A-Za-z\d]+([-_\.][A-Za-z\d]+)*@([A-Za-z\d]+[-\.])+[A-Za-z\d]{2,4}(,[A-Za-z\d]+([-_\.][A-Za-z\d]+)*@([A-Za-z\d]+[-\.])+[A-Za-z\d]{2,4})*$/
// 密码(在6~18之间，只能包含字母、数字和下划线)
const passRule = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/
const nameRule = /^[\u4E00-\u9FA5A-Za-z0-9_]+$/

function rexfunction(rexa: RegExp, value: any) {
    const reg = new RegExp(rexa)
        if(reg.test(value)) {
            return true
        }
        return false
}
function validator(rule: any, value: any, callback: any) {
    return (rexa: RegExp) => rexfunction(rexa, value)
}

function getTimer(createdAt: Date) {
    let timer = new Date(createdAt);
    let year = timer.getFullYear();      //转换成年
    let month = timer.getMonth() + 1; //转换成月 ，月注意要加1，因为外国月份是0 - 11月
    let day = timer.getDate();  //转换成日
    let hours = timer.getHours();  //转换成时
    let minutes = timer.getMinutes();  //转换成分
    // let secend = timer.getSeconds();  //转换成秒
    let str = `${(year)}年${(month)}月${(day)}号 ${(hours)}点${(minutes)}分`;
    return str;
}
export {
    validator,
    rexfunction,
    getTimer,
    emailRule,
    passRule,
    nameRule
}